Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disappearing undo steps after multiple selection changes #2792

Merged
merged 25 commits into from
Feb 19, 2019
Merged

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Feb 5, 2019

What is the purpose of this pull request?

Bug fix

Does your PR contain necessary tests?

All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

  • Prevent of firing applyFormat command after mouse up event, when there is no stored formatting.

Closes #2780.
Closes #2655.
Closes #2470.

@msamsel msamsel changed the base branch from major to master February 5, 2019 15:15
@mlewand mlewand added the review:easy Pull requests that can be reviewed by a Junior Developer before being reviewed by the Reviewer. label Feb 6, 2019
@engineering-this engineering-this self-assigned this Feb 6, 2019
Copy link
Contributor

@engineering-this engineering-this left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good, just some minor things.

I've found one more case which is even worse than originally reported. It is covered by your fix, but could you add test for that case too?


editable.attachListener( mouseupHost, 'mouseup', function( evt ) {
if ( getMouseButton( evt ) === CKEDITOR.MOUSE_BUTTON_LEFT ) {
if ( getMouseButton( evt ) === CKEDITOR.MOUSE_BUTTON_LEFT && cmd.state === CKEDITOR.TRISTATE_ON ) {

This comment was marked as resolved.

@@ -0,0 +1,13 @@
@bender-ui: collapsed
@bender-tags: bug, copyformatting, 4.11.3, trac16675
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong issue reference number.

Suggested change
@bender-tags: bug, copyformatting, 4.11.3, trac16675
@bender-tags: bug, copyformatting, 4.11.3, 2780

@bender-ckeditor-plugins: copyformatting, toolbar, wysiwygarea, undo, basicstyles

## Test both editors
1. Add some content to editor (e.g. new line), to "avctivate" undo step.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Suggested change
1. Add some content to editor (e.g. new line), to "avctivate" undo step.
1. Add some content to editor (e.g. new line), to "activate" undo step.

};

bender.test( {
'test undo integration': function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comment with ticket reference.

@msamsel
Copy link
Contributor Author

msamsel commented Feb 11, 2019

I add test cases which covers "redo" issue.

@engineering-this engineering-this self-assigned this Feb 11, 2019
Copy link
Contributor

@engineering-this engineering-this left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few more small things.

@@ -11,6 +12,26 @@
}
};

function prepareEditor( bot ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the function below bender.test, as we agreed to keep function declaration at the end.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if prepareEditor name works here. This function has plenty asserts and they aren't part of preparing editor.

CKEDITOR.replace( 'editor1' );
CKEDITOR.replace( 'editor1', {
on: {
instanceReady: function( evt ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listener function could be extracted to avoid duplicate code.
Additionally variable declarations could be grouped.


## Test both editors
1. Add some content to editor (e.g. new line), to "activate" undo step.
2. Start to click around editor to change selection inside editor (20-25 times). Selection have to differ between adjacent steps.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that adding empty lines between each test step improves readability.

instanceReady: function( evt ) {
var editor = evt.editor;
var currentIndicator = CKEDITOR.document.findOne( '#ed1-current' );
editor.editable().on( 'mouseup', function( evt ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evt param is unused, could be omitted.

1. Add some content to editor (e.g. new line), to "activate" undo step.
2. Start to click around editor to change selection inside editor (20-25 times). Selection have to differ between adjacent steps.
### Expected:
Undo UI button is active. Current snapshot index does equals 1 and doesn't change with selection change.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't change with selection change.

It updates only on mouse event so it's hard to tell if it's because of selection change or not. If we can't use other event like change maybe just go with interval. It will be much more convenient if index preview update weren't limited to user action.

}

assert.areSame( 1, editor.undoManager.index, 'There shouldn\'t be new undo steps and editor should remain on 1st step.' );
assert.isTrue( editor.undoManager.undoable(), 'Editor should has possibility to undo.' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.isTrue( editor.undoManager.undoable(), 'Editor should has possibility to undo.' );
assert.isTrue( editor.undoManager.undoable(), 'Editor should have a possibility to undo.' );

} ) );
}

assert.areSame( 1, editor.undoManager.index, 'There shouldn\'t be new undo steps and editor should remain on 1st step.' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.areSame( 1, editor.undoManager.index, 'There shouldn\'t be new undo steps and editor should remain on 1st step.' );
assert.areSame( 1, editor.undoManager.index, 'There shouldn\'t be new undo steps and editor should remain on the 1st step.' );

Copy link
Contributor

@engineering-this engineering-this left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setInterval doesn't improve test, as second (after initial) snapshot is created when selection changes so it might be misleading for tester when he types something and index preview updates on click. Maybe we should just drop the preview of snapshot index and just repeat steps from originally reported issue.

@msamsel
Copy link
Contributor Author

msamsel commented Feb 14, 2019

PR related to: #2811

@Comandeer
Copy link
Member

I cherry-picked tests from #2811. I've also updated unit test for undo to behave correctly in IE 8 (as it uses non-standard code for left mouse button).

@msamsel msamsel assigned msamsel and unassigned msamsel Feb 15, 2019
@msamsel msamsel assigned msamsel and unassigned msamsel Feb 15, 2019
@engineering-this engineering-this self-assigned this Feb 15, 2019
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:easy Pull requests that can be reviewed by a Junior Developer before being reviewed by the Reviewer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants